(function(){
    angular.module('feibo.teacher.controller').controller('TeacherContractCheckController', TeacherContractCheckController);

    TeacherContractCheckController.$inject = ['$stateParams', 'TeacherService'];

    function TeacherContractCheckController($stateParams, TeacherService){
        var vm = this;

        vm.data = {
            contractId: $stateParams.contractId,
            contract: undefined
        };

        vm.initData = function(){
            vm.getTeacherContract();
        };

        vm.getTeacherContract = function(){
            var data = vm.data;
            var queryConfig = {
                funcName: 'getTeacherContract',
                container: data,
                propName: 'contract',
                propChain: ['data'],
                showLoadLayer: false,
                urlPlaceholder: {
                    id: data.contractId
                }
            };

            TeacherService.getTeacherContract(queryConfig).then(function(returnedData){
                if(returnedData.success && returnedData.data.teacher_pack){
                    returnedData.data.teacher_pack.forEach(function(val, index){
                        vm.getClassType(val.fb_shift_category_id, index);
                    });
                }
            }).catch(function(error){
                console.error(error);
            });
        };

        // 查询单个班型大类
        vm.getClassType = function(id, index){
            var queryConfig = {
                funcName: 'getClassType',
                propChain: [],
                showLoadLayer: false,
                urlPlaceholder: {
                    id: id
                }
            };

            TeacherService.getClassType(queryConfig).then(function(returnedData){
                if(returnedData.success){
                    vm.data.contract.teacher_pack[index].fb_shift_category_name = returnedData.data.name;
                }
            }).catch(function(error){
                console.error(error);
            });
        };

        // 查询单个班型小类
        vm.getClassMiniType = function(id, index){
            var queryConfig = {
                funcName: 'getClassMiniType',
                propChain: [],
                showLoadLayer: false,
                urlPlaceholder: {
                    id: id
                }
            };

            TeacherService.getClassMiniType(queryConfig).then(function(returnedData){
                if(returnedData.success){
                    vm.data.contract.teacher_pack[index].fb_shift_name = returnedData.data.name;
                }
            }).catch(function(error){
                console.error(error);
            });
        };
    }
}());
